// pages/me_content/location.js
import { getAddrList } from '../api/index';
import { store } from '../../store/index';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    addrList: [],
    type: null
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onShow() {
    this.getAddrList();
  },
  onLoad(options) {
    if (options.type) {
      this.setData({
        type: options.type
      });
    }
  },
  getAddrList() {
    getAddrList().then(res => {
      console.log(res, 'res');
      this.setData({
        addrList: res.result
      });
    });
  },
  selectAddr(e) {
    if (!this.data.type) {
      return;
    }
    const id = e.currentTarget.dataset.id;
    store.updateSelectAddrData(this.data.addrList.find(item => item.id === id));
    wx.navigateBack();
  },
  editLocation(e) {
    const id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/me/locationEdit/index?id=' + id
    })
  },
  addLocation() {
    wx.navigateTo({
      url: '/pages/me/locationEdit/index'
    })
  }
})